<template>
  <el-container style="width: 100%;height: 100%">
    <el-header style="height: 80px;">
      <div class="logo"><img src="../../static/img/logo.png"></div>
      <div class="title">数字货币交易系统——运营平台</div>
      <div class="user">
        <span style="color:#ffffff;font-size:14px;cursor:pointer;">
          您好,{{userName}}
        </span>
        <!--<el-dropdown trigger="click">-->
          <!--<span style="color:#ffffff;font-size:14px;cursor:pointer;">-->
            <!--您好,{{userName}}-->
          <!--</span>-->
          <!--<el-dropdown-menu slot="dropdown">-->
            <!--<el-dropdown-item @click="logOut">退出</el-dropdown-item>-->
          <!--</el-dropdown-menu>-->
        <!--</el-dropdown>-->
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-active="$route.path" unique-opened router class="my-menu" background-color="#243444" text-color="#fff" >
          <el-submenu v-for="(menu , index) in $router.options.routes" :index="'一级'+index" :key="index" v-if="(!menu.isHidden)&&menuList.indexOf(menu.name)>-1">
            <template slot="title">
              <span>{{menu.name}}</span>
            </template>
            <el-menu-item v-for="(subMenu , subIndex) in menu.children" :index="subMenu.path" :key="subIndex" v-if="menuList.indexOf(subMenu.name)>-1">
              <span>{{subMenu.name}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container class="main-con">
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
  import server from '../services/index'
  export default {
    name: 'Home',
    components: {  },
    data () {
      return {
        userName: "",
        menuList: "",
      }
    },
    methods:{
      logOut(){
        // todo 预留退出
      },
      getMenuList(){
        $.ajax({
          url:server.menuList.url + '/' + sessionStorage.getItem('roleId'),
          type:'get',
          data:{roleId:sessionStorage.getItem('roleId')},
          dataType:'json',
          success:res => {
            if(res.code == 1){
              var menuStr = '';
              res.result.userList.forEach(item => {
                menuStr += item.menuName + ',';
              })
              this.menuList = menuStr;
            }
          },
        });
      },
    },
    mounted(){
      this.userName = sessionStorage.getItem('userName');
      this.getMenuList();
    },
  }
</script>
<style scoped>
  header{
    padding: 20px;
    width: 100%;
    height: 60px;
    background: #243444;
    color: #fff;
    display: flex;
    align-items: center;
  }
  .logo{
    width: 63px;
    height: 40px;
    margin: 0 20px 0 20px;
  }
  .el-aside{
    position: absolute;
    height: 100%;
    top: 80px;
    bottom: 0;
    background: #243444;
  }
  .main-con{
    position: absolute;
    height: 100%;
    left: 200px;
    right: 0;
    top: 80px;
    bottom: 0;
    background: #e4eaf6;
  }
  .el-menu{
    height: 100%;
    overflow: hidden;
  }
  .el-main{
    margin: 20px;
    background: #ffffff;
  }
  .user{
    position: absolute;
    right: 40px;
  }
  .pagination{
    margin-top: 20px;
  }
</style>
